﻿using Cofe.Core;
using Cofe.Core.Dynamic;
using Cofe.Core.Property;
using Cofe.IO;
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Cofe.Media;

namespace Cofe.Media
{
    [Export(typeof(ICofeService))]
    [ServicePriority(ServicePriorityAttribute.DefaultPriority_COFEIO)]
    public class MediaInterfaceProvider : IDynamicPropertyInterfaceProvider
    {
        public bool CanCastAs<T>(IPropertyHost input) where T : IDynamicInterface<IPropertyHost>
        {
            if (typeof(T) == typeof(IImageInfo))
                return input.SupportedDefinitions.Contains(PropertyDefinitions.ExifPropDefinitions,
                    PropertyDefinitionComparer.CompareCategory);
            return false;
        }

        public T CastAs<T>(IPropertyHost input) where T : IDynamicInterface<IPropertyHost>
        {
            if (CanCastAs<T>(input))
            {
                if (typeof(T) == typeof(IImageInfo))
                {
                    return (T)(IImageInfo)new ImageInfo(input);
                }

            }
            throw new NotSupportedException();
        }

        public Type[] CastableInterfaces
        {
            get { return new Type[] { typeof(IImageInfo) }; }
        }


        public Type[] CastableContainers
        {
            get { return new Type[] { typeof(ImageInfo)}; }
        }
    }
}
